package com.bnlr.lrparking.appui.mine.collection;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.bnlr.lrparking.R;
import com.bnlr.lrparking.adapter.SynthesizeAdapter;
import com.bnlr.lrparking.appui.mine.collection.fragment.CarPlaceCollectFragment;
import com.bnlr.lrparking.appui.mine.collection.fragment.ParkingCollectFragment;
import com.bnlr.lrparking.view.NoSlideViewPager;
import com.bnlr.lrparking.widget.PopupCollectBox;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 *
 * @author Administrator
 * date 2017/6/7
 * 我的收藏
 *
 */

public class MyCollectActivity extends FragmentActivity {

    private Unbinder unbinder;
    @BindView(R.id.check_place_type)
    PopupCollectBox popupCheckBox;
    @BindView(R.id.tv2)
    TextView tv2;
    @BindView(R.id.tv22)
    TextView tv22;
    @BindView(R.id.tv11)
    TextView tv11;
    @BindView(R.id.no_slide_pager)
    NoSlideViewPager mViewPager;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private CarPlaceCollectFragment fragment;
    private int positionIndex = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        setContentView(R.layout.activity_my_collect);
        unbinder = ButterKnife.bind(this);
        fragment = new CarPlaceCollectFragment();
        mFragments.add(fragment);
        mFragments.add(new ParkingCollectFragment());
        mViewPager.setOffscreenPageLimit(mFragments.size() - 1);
        mViewPager.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager()));
        initCategoryPop();
    }
    @OnClick({R.id.rl_check,R.id.check_place_type,R.id.tv2,R.id.iv_back})
    public void myCollectClick (View view) {
        switch (view.getId()) {
            case R.id.check_place_type:
                mViewPager.setCurrentItem(0);
                tv11.setBackgroundColor(getResources().getColor(R.color.main_color));
                popupCheckBox.setTextColor(getResources().getColor(R.color.main_color));
                tv2.setTextColor(getResources().getColor(R.color.text_hint));
                tv22.setBackgroundColor(getResources().getColor(R.color.bg));
                popupCheckBox.setChecked(true);
                popupCheckBox.setNeedShow(true);
                break;
           /* case R.id.check_place_type:

                mViewPager.setCurrentItem(positionIndex);
                tv11.setBackgroundColor(getResources().getColor(R.color.main_color));
                popupCheckBox.setTextColor(getResources().getColor(R.color.main_color));
                tv2.setTextColor(getResources().getColor(R.color.text_hint));
                tv22.setBackgroundColor(getResources().getColor(R.color.bg));

                break;*/
            case R.id.tv2:
                mViewPager.setCurrentItem(1);
                tv2.setTextColor(getResources().getColor(R.color.main_color));
                tv22.setBackgroundColor(getResources().getColor(R.color.main_color));
                tv11.setBackgroundColor(getResources().getColor(R.color.bg));
                popupCheckBox.setTextColor(getResources().getColor(R.color.text_hint));
                popupCheckBox.hidePopup();
                popupCheckBox.setNeedShow(false);
                break;
            case R.id.iv_back:
                finish();
                break;
            default:
                break;
        }
    }
    private void initCategoryPop() {
        View view = View.inflate(this,R.layout.pop_stall_chuzu_list,null);
        initCategoryView(view);
        popupCheckBox.setPopupView(view,600);
    }

    private void initCategoryView(View view) {
        ListView listView=(ListView) view.findViewById(R.id.rv_stall_chuzu_list);
        final String[] strstallsynthesize = new String[]{"全部车位","出租车位", "出售车位", "求租车位","求购车位",};
        final SynthesizeAdapter synthesizeAdapter=new SynthesizeAdapter(this,strstallsynthesize);
        listView.setAdapter(synthesizeAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                synthesizeAdapter.setSelectPosition(position);
                popupCheckBox.setText(strstallsynthesize[position]);
                popupCheckBox.hidePopup();
                String type = "0";
                switch (position) {
                    case 0:
                        type = "0";
                        break;
                    case 1:
                        type = "10";
                        break;
                    case 2:
                        type = "11";
                        break;
                    case 3:
                        type = "20";
                        break;
                    case 4:
                        type = "21";
                        break;
                    default:
                        break;
                }
                fragment.newInstance(type);
            }
        });
    }

    public class MyViewPagerAdapter extends FragmentPagerAdapter {
        public MyViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }
        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
        @Override
        public int getCount() {
            return mFragments.size();
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
}
